$(function () {
    // 进入页面先查看登录状态
    if (localStorage.getItem('token')) {
        $(".login").css({'display':'none'})
        $(".login-success").css({ 'display': 'block' })
    } else {
        $(".login").css({ 'display': 'block' })
        $(".login-success").css({ 'display': 'none' })
    }

    // 跳转登录
    $(".login").click(function () {
        location.href = "../../loginPage.html"
    })

    // 获取ApiKey
    $(".getApiKey").click(function () {
        axios({
            url: 'http://106.53.218.88:10010/user/key',
        }).then(res => {
            console.log(res.data);
            layer.tips(`ApiKey：${res.data}`, this, {
                tips: 3,
                time:7000
            })
        }).catch(error => {
            console.log(error);
        })
    })

    layui.use(function () {
        // code
        layui.code({
            elem: '.code-demo',
            tools: ['copy'],
            toolsEvent: function (obj) {
                layer.msg('复制成功', { icon: 1 })
            },
            lang: 'java',
            langMarker:true,
            wordWrap: true,
            header: true,
        });
    })


    // http request拦截器 添加一个请求拦截器
    axios.interceptors.request.use(function (config) {
        if (localStorage.getItem("token")) {
            config.headers.token = localStorage.getItem("token");
            return config;
        }
    }, function (error) {
        console.log(error);
        return Promise.reject(error);
    });
})

